import random

suit_value = ('spade', 'diamond', 'heart', 'club', 'redjoker', 'blackjoker')
number_value = ('A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'redjoker', 'blackjoker')

class poker:
    def __init__(self, s, n):
        self.suit = suit_value[s]
        self.number = number_value[n]
    def show(self):
        if self.suit != 'redjoker' and self.suit != 'blackjoker':
            print(self.suit, self.number)
        else:
            print(self.suit)

class deck:    
    def __init__(self, name):
        self.cards = list()
        self.owner = name
        if name == 'PUBLIC':    #公共牌堆初始化，包括3副牌共162张牌，4位玩家抽牌完成后剩余6张作为底牌
            for k in range(3):
                for i in range(4):
                    for j in range(13):
                        self.cards.append(poker(i,j))
                self.cards.append(poker(4, 13))
                self.cards.append(poker(5, 14))        
    def draw(self, targetDeck, num):    #从目标牌堆摸数张牌
        if len(targetDeck.cards):
            for i in range(num):
                self.temp = random.choice(targetDeck.cards)
                #print('draw',self.temp.suit,self.temp.number,'from',targetDeck.owner)
                targetDeck.cards.remove(self.temp)
                self.cards.append(self.temp)
            print(self.owner,'has draw',num,'card(s) from',targetDeck.owner)
        else:
            print(targetDeck.owner, '\'s deck is empty!')
    def dealing(self):     #发牌阶段，每位玩家抽39张牌
        self.draw(PUBLIC, 39)
    def show(self):     #亮出所有手牌
        for i in range(len(self.cards)):
            self.cards[i].show()

def gamestart():    #用于开始游戏
    player1.dealing()
    player2.dealing()
    player3.dealing()
    player4.dealing()
    print('players have finished dealing.\nGAME START!')

PUBLIC = deck('PUBLIC')
player1 = deck('player1')
player2 = deck('player2')
player3 = deck('player3')
player4 = deck('player4')
